/**
 * Remove all elements from a linked list of integers that have value val.
 * Example
 * Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6
 * Return: 1 --> 2 --> 3 --> 4 --> 5
 */

 /**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* removeElements(struct ListNode* head, int val) {
    struct ListNode * curPtr;
    if (head == 0) return head;
    for (int i = 0; head->val == val; i++) {
        head = head->next;
        if (!head) return head;
    }
    curPtr = head;
    for (int i = 0; curPtr->next != 0; i++) {
        if (curPtr->next->val == val)
            curPtr->next = curPtr->next->next;
        else
            curPtr = curPtr->next;
    }
    return head;
}